package org.adream.account.rest.api;

import org.adream.account.model.ResultModel;
import org.adream.account.rest.api.model.LoginStateSearchForm;
import org.adream.account.service.LoginStateService;
import org.adream.account.util.Constant;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * 用户登录状态api
 * @author sl
 *
 */
@RestController
@RequestMapping("loginState")
public class LoginStateApiController {
	
	@Autowired
	private LoginStateService loginStateService;
	
	private final static Logger logger = LoggerFactory.getLogger(LoginStateApiController.class);
	
	/**
	 * 分页查询登录异常名单
	 * @param form
	 * @return
	 */
	@RequestMapping(value = "/queryUserLoginStateExceptions", produces = "application/json;charset=UTF-8", method = RequestMethod.POST)
	public ResultModel<?> queryUserLoginStateExceptions(@RequestBody LoginStateSearchForm form) {
		if(form == null || form.getDr() == null) {
			logger.warn("查询失败,参数为空:(");
			return new ResultModel<String>(ResultModel.ERR_PARAM, "查询失败,参数为空", null);
		}
		if(form.getPageNo() == null) {
			form.setPageNo(Constant.ONE);
		}
		if(form.getPageSize() == null) {
			form.setPageSize(Constant.TEN);
		}
		return loginStateService.queryUserLoginStateExceptions(form.getUid(), form.getDr(), form.getPageNo(), form.getPageSize());
	}
	
	/**
	 * 删
	 * @param uid
	 * @return
	 */
	@RequestMapping(value = "deleteLoginState", produces = "application/json;charset=UTF-8", method = RequestMethod.POST)
	public ResultModel<?> deleteLoginState(String uid) {
		if(StringUtils.isEmpty(uid)) {
			logger.warn("删除失败,参数为空:(");
			return new ResultModel<String>(ResultModel.ERR_PARAM, "删除失败,参数为空", null);
		}
		return loginStateService.deleteLoginState(uid);
	}
}
